package com.loveprogrammer.cloud.controller;

import com.loveprogrammer.cloud.entity.Order;
import com.loveprogrammer.cloud.service.OrderService;
import com.sun.org.apache.xpath.internal.operations.Or;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.UUID;

/**
 * @author java1234_小锋
 * @site www.java1234.com
 * @company 南通小锋网络科技有限公司
 * @create 2021-07-14 11:13
 */
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    /**
     * 创建订单
     * @param order
     * @return
     */
    @PostMapping("/create")
    public boolean createOrder(@RequestBody Order order){
        System.out.println("order:"+order);

        order.setOrderNo(UUID.randomUUID().toString());  // 生成订单ID
        orderService.createOrder(order);
        return true;

    }

    /**
     * 获取订单
     * @param id
     * @return
     */
    @PostMapping("/get")
    public Order createOrder(@RequestParam Integer id){
        System.out.println("get order by id: "+id);

        return orderService.getOrderById(id);

    }
}
